<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *养殖管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
}
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'养殖列表'),
);
$return['status']=array('0'=>'待确认','1'=>'已确认');
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','number','uniacid','animal_id','mid','order_id','stage','feeding','water','status','createtime');
	$list=pdo_getslice('jy_farmer_adopt',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$animal=pdo_get('jy_farmer_animal',array('id'=>$item['animal_id'],'uniacid'=>$_SESSION['uniacid']));
			$item['aclassify_title']=pdo_getcolumn('jy_farmer_aclassify',array('id'=>$animal['classify_id'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['animal_title']=$animal['title'];
			$item['createtime']=date('Y-m-d h:i',$item['createtime']);
			$item['member']=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']));
			$stage=$animal['stage']?json_decode($animal['stage'],true):array();
			$item['stage']=$stage[$item['stage']]['stage_name'];
			$item['order']=pdo_get('jy_farmer_order',array('id'=>$item['order_id'],'uniacid'=>$_SESSION['uniacid']),array('username','total'));
			if($item['number']<10){
				$item['number']='000'.$item['number'];
			}elseif($item['number']<100 && $item['number']>9){
				$item['number']='00'.$item['number'];
			}else{
				$item['number']='0'.$item['number'];
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member.nickname','title'=>'用户昵称','type'=>'string'),
			array('name'=>'order.username','title'=>'用户姓名','type'=>'string'),
			array('name'=>'aclassify_title','title'=>'家禽分类名称','type'=>'string'),
			array('name'=>'animal_title','title'=>'家禽名称','type'=>'string'),
			array('name'=>'number','title'=>'编号','type'=>'string'),
			array('name'=>'stage','title'=>'生长状态','type'=>'string'),
			array('name'=>'createtime','title'=>'养殖时间','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		)),
		'search'=>array(
			array('name'=>'username','width'=>15,'title'=>'用户姓名','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
//待消费
